<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>实现一个盒子水平居中</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        /* 第一种方法 margin:0 auto */
        .box1{
            width:200px;
            height:200px;
            background-color: skyblue;
            margin:10px auto;
        }
        /* 第二种方法，利用定位和css中的位移 */
        .box2{
            width:400px;
            height:400px;
            border:1px solid blue;
            position: relative;
            margin: 0 auto;
        }

        .box2 p{
            position: absolute;
            width:200px;
            height:200px;
            background-color: skyblue;
            top:50%;
            left: 50%;
            transform: translateX(-50%) translateY(-50%);
        }
    </style>
</head>
<body>
    <div class="box1"></div>

    <div class="box2">
        <p class="innerbox"></p>
    </div>
</body>
</html>